package scott;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import scott.util.JdbcTemplate;

import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import javax.swing.JDialog;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TableFrame extends JFrame {

	private JPanel contentPane;
	private JTable table_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TableFrame frame = new TableFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TableFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 777, 526);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(71, 63, 610, 370);
		contentPane.add(scrollPane);
		
		table_1 = new JTable();
		scrollPane.setViewportView(table_1);
		
		///////////////////////////////////////////////////////////////////////////////
		
		List<Map<String,Object>> list = JdbcTemplate.queryList("select * from emp");
		Vector<String> head = new Vector<>();
		head.add("员工编号");
		head.add("员工姓名");
		head.add("员工岗位");
		Vector<Vector<Object>> data = new Vector<>();
		for(int i=0; i<list.size();i++) {
			Vector<Object> row = new Vector<>();
			row.add(list.get(i).get("EMPNO"));
			row.add(list.get(i).get("ENAME"));
			row.add(list.get(i).get("JOB"));
			data.add(row);
		}
		
		TableModel model = new DefaultTableModel(data, head);
		table_1.setModel(model);
		
	}
}
